<template>
	<view>
		<view class="goodsBox" :style="{marginBottom:bottom}" v-for="(item,index) in dataList.rows" :key="index"
			@click="goodsItem(item)">
			<view class="goodsBox-top">
				<view class="leftBox">
					<image class="goodsImg" mode="aspectFill" :src="setImgs(item.commodityFile)[0]"></image>
				</view>
				<view class="rightBox">
					<view class="goodsTitle">{{item.commodityName}}</view>
					<view class="goodsAddress">{{item.businessName}}</view>
					<view class="goodsSalesBox">
						<text class="goodsSales">已换{{item.exchange||0}}份</text>
						<text class="goodsSales">库存{{item.inventory||0}}份</text>
					</view>
					<view class="goodsPrice">{{item.integral}}积分</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "goods",
		props: {
			bottom: {
				type: String,
				default: '40rpx'
			}
		},
		data() {
			return {
				dataList: [],
				imgList: []
			};
		},
		methods: {
			setImgs(imgs) {
				let list = []
				if (typeof imgs == 'string') {
					list = imgs.split(',')
				} else {
					list = imgs
				}
				let list1 = []
				list1 = list.map(item => this.$setImgUrl(item))
				return list1
			},
			goodsItem(data) {
				this.$emit('click', data)
			},
			initData(data) {
				console.log(data);
				this.dataList = data
			},
		}
	}
</script>

<style lang="scss" scoped>
	.goodsBox {
		margin-bottom: 40rpx;

		.goodsBox-top {
			display: flex;
			align-items: flex-start;
			margin-bottom: 16rpx;

			.leftBox {
				flex-shrink: 0;
				margin-right: 16rpx;

				.goodsImg {
					width: 140rpx;
					height: 140rpx;
					object-fit: cover;
				}
			}

			.rightBox {
				.goodsTitle {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #000000;
				}

				.goodsAddress {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #000000;
					margin: 8rpx 0;
				}

				.goodsSalesBox {
					.goodsSales {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #979797;
						margin-right: 20rpx;
					}
				}
				
				.goodsPrice {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					color: #ffaa00;
				}
			}
		}

		.goodsBox-Bottom {
			padding-left: 156rpx;
			display: flex;
			align-items: center;

			.btnBox {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				width: 136rpx;
				height: 60rpx;
				border-radius: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.btn {
				color: #FFFFFF;
				border: 0px none;
				margin-right: 20rpx;
				background: linear-gradient(90deg, #5F96E8 0%, #1977E1 100%);
			}

			.btn1 {
				color: #0138D2;
				border: 2rpx solid #0138D2;
			}
		}
	}
</style>